<?php

namespace App\V3\V3_2_7\Models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class BarterDriverModel extends Model
{
    use HasFactory;

    protected $table = 'barter_driver';

    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储
    //toArray 时间转换问题
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }
    
    /**
     * 查询换货单司机信息
     * @param unknown $userId
     * @param unknown $data
     */
    static public function getBarterDriver($userId, $data){
    return SELF::select('barter_id')
        ->where([
            'main_id' => $data['main_id']
        ])
        ->where(function($query) use($data){
            $query->where('name', 'like', '%'.$data['keyword'].'%');
        })->get()->toArray();
    }
}
